package com.jn.exam.webSocket.config;

import com.jn.exam.webSocket.utils.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置rabbitmq
 *
 * @author 江南大学1033190417
 * @date 2022/3/4 20:24
 */
@Configuration
public class ExchangeConfiguration {

    private static Logger logger= LoggerFactory.getLogger(ExchangeConfiguration.class);

    @Autowired
    private ServerConfig serverConfig;

    @Bean
    public FanoutExchange fanoutExchange(){
        logger.info("【【创建交换机】】");
        return new FanoutExchange(Constants.FANOUT_EXCHANGE_NAME);
    }

    @Bean
    public Queue queue(){
        logger.info("【【创建队列】】");
        return new Queue(Constants.QUEUE_NAME+"——"+serverConfig.getUrl());
    }

    @Bean
    public Binding bindingQueueToExchange(){
        logger.info("【【队列绑定交换机】】");
        return BindingBuilder.bind(queue()).to(fanoutExchange());
    }
}
